<?php


namespace App\Services\Aliyun\Identify;


use App\Services\Aliyun\BaseService;
use App\Services\Configs\DefaultService;

class IdCard extends BaseService
{
    private $url;
    private $appcode;

    public function __construct()
    {
        $config = $this->getConfig(DefaultService::ALI_IDENTIFY);
        $this->url = $config['url'];
        $this->appcode = $config['appcode'];
    }

    /**
     * 身份证二要素校验
     * @param $cardNo 身份证号
     * @param $realName 真实姓名
     * @return bool
     * @author an
     * @time 2021-12-06 14:44
     */
    public function checkNoName($cardNo, $realName)
    {
        $url = $this->url . "/idcheck/Post";
        $headers = array();
        array_push($headers, "Authorization:APPCODE " . $this->appcode);
        //根据API的要求，定义相对应的Content-Type
        array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8");
        $bodys = "cardNo={$cardNo}&realName={$realName}";
        $data = $this->request($url, $bodys, $headers);
        $data = json_decode($data, true);
        if (empty($data)) {
            return false;
        }
        $result = $data['result'];
        if (isset($data['error_code']) && $data['error_code'] == 0 && $result['isok'] === true) {
            return true;
        } else {
            return false;
        }
    }

    //身份证正面校验
    public function checkFront()
    {

    }

    //身份证反面校验
    public function checkBack()
    {

    }
}
